<template>
  <div class="recognize">
    <div class="verification">
      <gz-face-verification-old
        :identityinfo="identityInfo"
        v-model="result" v-if="showFace"
      ></gz-face-verification-old>
    </div>
    <div class="authorization">
      <gz-authorization
        :fileinfo="fileinfoRule"
        :identityinfo="identityinfoRule"
        v-model="isReadly"
      ></gz-authorization>
    </div>
    <div class="footer">
      <x-button type="warn" @click.native="save">保存</x-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "recognize",
  props: {
    identityinfo: {
      //身份信息
      type: Object,
      default: () => {
        return {
          /*
             {idCard: '',name: ''}
             */
        };
      },
    },
    fileinfo: {
      //pdf文件相关内容
      type: Array,
      default: () => {
        return [
          /*
              {
              	name:'对外提供个人信息授权书',
              	url: 'http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf',
                time: 2
              }
 */
        ];
      },
    },
    instid: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      isReadly: false,
      result: null,
      instId: this.instid || "",
      fileinfoRule: [
        { name: "对外提供个人信息授权书", key: "network" },
        // { name: "人脸识别授权书", key: "faceRecognition" },
        { name: "个人征信客户授权书", key: "creditInvestigation" },
        { name: "个人信息及敏感信息授权书", key: "sensitive" },
        { name: "纳税人涉税信息查询授权书", key: "information" },
      ],
      identityinfoRule: {
        personalFlag: false, //（是否个人授权书）
        xtlsh: "", //（系统流水号）
        cardName: "", //（身份证类型名称）  000101
        cardCode: "", //（身份证号）
        authorizedName: "", //（客户姓名）
      },
      identityInfo: this.identityinfo.idCard ? this.identityinfo : {},
      showFace: false
    };
  },
  created() {
    let instId = this.$route.query.instId;
    let personalFlag = this.$route.query.personalFlag
      ? this.$route.query.personalFlag
      : false;
    if (!this.instId && instId) {
      this.instId = instId;
    }
    this.getint().then((login) => {this.getIdentityInfo(instId,personalFlag)});
  },
  mounted() {

  },
  methods: {
    getIdentityInfo(instId,personalFlag) {
      this.baseService
        .get(this.__ctx + "/cifPer/exp/" + instId)
        .then((data) => {
          if (data.isOk) {
            this.identityinfoRule = {
              personalFlag: personalFlag == "true" ? true : false,
              xtlsh: data.data.instId,
              cardName: data.data.cardName,
              cardCode: data.data.cardCode,
              authorizedName: data.data.authorizedName,
            };
            this.identityInfo = {
              idCard: data.data.cardCode,
              name: data.data.authorizedName,
              instId: instId,
              fileType: 'IML010201'
            }
          } else {
            this.abTools.toast(data.msg, "warn");
          }
          this.showFace = true
        });
    },
    getint() {
      // 获取token是http://localhost:8080/biz/loginBy/jwtForMobile（行内）参数是account默认wxApplets、audience默认Applets
      //微信银行 account/audience: wxBank, 手机银行 account/audience: mobileBank
      return new Promise((resolve) => {
        let defer = this.baseService.postForm(
          this.__ctx + "/biz/loginBy/jwtForMobile",
          {
            account: process.env.account, //默认
            audience: process.env.account, //默认
          }
        );
        defer.then((data) => {
          if (data.isOk) {
            resolve();
          } else {
            this.$vux.toast.show({
              type: "warn",
              text: data.msg,
            });
          }
        });
      });
    },
    save() {
      if (!this.result || Number(this.result) != 1) {
        this.abTools.toast("请先通过人脸验证！", "warn");
        return false;
      }
      if (!this.isReadly) {
        this.abTools.toast("请同意签署授权书！", "warn");
        return false;
      }
      let params = {
        instId: this.instId
      }
      this.baseService
        .postForm(this.__ctx + "/cifPer/exp/updateFaceData",params).then((data) => {
          if (data.isOk) {
            this.abTools.toast("更新成功", "sucess");
          } else {
            this.abTools.toast(data.msg, "warn")
          }
        });
    },
  },
  watch: {},
};
</script>

<style lang="less" scoped>
.recognize {
  padding: 1rem;
  .footer {
    padding: 1rem;
  }
}
</style>
